﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;

namespace Shadowsocks.Encryption
{
    class MSaes
        :EncryptorBase
    {
        public MSaes(string method, string password)
            :base(method, password)
        {
            AesCryptoServiceProvider provider = new AesCryptoServiceProvider();
            byte[] passbuf = Encoding.UTF8.GetBytes(password);
            byte[] key = new byte[32];
            bytesToKey(passbuf, key);
        }

        protected void bytesToKey(byte[] password, byte[] key)
        {
            byte[] result = new byte[password.Length + 16];
            int i = 0;
            byte[] md5sum = null;
            while (i < key.Length)
            {
                MD5 md5 = MD5.Create();
                if (i == 0)
                {
                    md5sum = md5.ComputeHash(password);
                }
                else
                {
                    md5sum.CopyTo(result, 0);
                    password.CopyTo(result, md5sum.Length);
                    md5sum = md5.ComputeHash(result);
                }
                md5sum.CopyTo(key, i);
                i += md5sum.Length;
            }
        }

        public override void Encrypt(byte[] buf, int length, byte[] outbuf, out int outlength)
        {
            throw new NotImplementedException();
        }

        public override void Decrypt(byte[] buf, int length, byte[] outbuf, out int outlength)
        {
            throw new NotImplementedException();
        }

        public override void Dispose()
        {
            throw new NotImplementedException();
        }
    }
}
